1
开发者提示工程基础
AI010Lesson 1
00:00

向指令微调模型的转变

其基础是什么?

过去,基础大语言模型主要通过海量数据来预测序列中的下一个词。然而对开发者而言,真正的强大之处在于指令微调的大语言模型。这些模型通过使用基于人类反馈的强化学习(RLHF)进行优化,以遵循特定指令并充当得力助手。

黄金法则:将大语言模型视为一位聪明但字面理解的实习生。它缺乏你的具体上下文,因此你必须明确表达目标。

如何应用核心原则

  1. 清晰与具体性 清晰并不等于简洁。提供更多上下文并使用分隔符(如三重反引号或XML标签)有助于模型区分你的指令和需要处理的数据。
  2. 给模型留出思考时间: 复杂任务需要一个思维链。如果你要求模型直接得出结论,它更可能犯推理错误。应先指示它自行推导解决方案。
避免幻觉
模型可能生成听起来合理但不真实的信息。务必核实事实,或指示模型引用来源,以降低此风险。
main.py
TERMINALbash — 80x24
> Ready. Click "Run" to execute.
>
Question 1
Why should a developer prefer an Instruction Tuned LLM over a Base LLM for building an application?
Base LLMs are better at following complex instructions.
Instruction Tuned LLMs are trained to follow tasks and are less likely to simply "complete" the text.
Base LLMs never hallucinate.
Challenge: Generating Structured Data
Apply prompting principles to format output.
You have a list of ingredients. You need to convert this list into a JSON format for a web app.
Task
Write a prompt that requests JSON output with keys for 'item' and 'quantity'. Include a condition check: If the input is not a recipe, output "No recipe detected."
Solution:
prompt = "You will be provided with text. If it contains a recipe, convert it to JSON with keys 'item' and 'quantity'. If not, write 'No recipe detected.' Text: <user_input>"